package com.fengmi.service.impl;

import com.fengmi.entity.StatOrder;
import com.fengmi.mapper.StatOrderMapper;
import com.fengmi.service.StatOrderService;
import com.fengmi.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class StatOrderServiceImpl implements StatOrderService {

    @Autowired
    private StatOrderMapper statOrderMapper;

    @Override
    @Scheduled(cron = "0 0 1 * * ?")
    public ResultVO statOrderPerDay() {
        //先统计
        StatOrder totalForYesterday = statOrderMapper.findTotalForYesterday();

        //再写入
        statOrderMapper.saveOrderTotalInfo(totalForYesterday);

        return new ResultVO(true,"昨日订单统计保存完毕");
    }

    @Override
    public ResultVO statOrderByTime(String beginTime, String endTime) {
        List<StatOrder> orderList = statOrderMapper.statOrderByDate(beginTime, endTime);
        return new ResultVO(true,"查询订单信息成功",orderList);
    }
}
